<!DOCTYPE html>
<html>
    <head>

    </head>
    <body>
      <div>
          <textarea oninput="checkText()" style="height:100px;width:200px" id ="textContent"
          name="content" style="overflow-y:scroll ;">

          </textarea>
      </div>
      <div>
          已输入<span style="font-family: Georgia;font-size: 26px;"id="write">0</span>
          还可以输入<span style="font-family: Georgia;font-size: 26px;" id= "leftText">140</span>个字
        </div>
        <script type="text/javascript">
            var textContent = document.getElementById("textContent");
            var leftText = document.getElementById("leftText")
            var write = document.getElementById("write");
            function checkText(){
                var max =140;
                if(textContent.value.length>max){
                    textContent.value = textContent.value.substring(0,max);
                    leftText.innerText=0;
                    alert("不能超过"+max+"个字")
                }else{
                    write.innerText = textContent.value.length;
                    leftText.innerText = max-textContent.value.length;
                } 
            }
            
            

</script>
    </body>
</html>